{include file='header'/}
<body>
<form class="layui-form" action="javascript:;">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label required">所属分组</label>
                <div class="layui-input-block">
                    <select name="group_id" lay-verify="required">
                        <option value="">请选择分组</option>
                        {foreach link_group_name as $key=>$val}
                        <option value="{$key}" <?php if($data['group_id'] == $key) echo "selected" ?>>{$val}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">链接名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" lay-verify="required" autocomplete="off"
                           placeholder="请输入链接名称" class="layui-input" value="{$data.name}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">链接地址</label>
                <div class="layui-input-block">
                    <input type="text" id="src" name="src" lay-verify="required|url" autocomplete="off"
                           placeholder="请输入链接地址" class="layui-input" value="{$data.src}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">logo图片</label>
                <div class="layui-input-block huicmf-upload">
                    <input type="text" name="logo" value="{$data.logo}"
                           id="thumb-select-input" autocomplete="off" class="layui-input">
                    <button type="button" class="layui-btn layui-btn-normal layUpload" id="picker_pic2"
                            data-multiple="false" data-input-id="thumb-select-input"
                            data-preview-id="thumb" data-type="image"><i class="layui-icon"></i>上传图片
                    </button>
                    <button type="button" class="layui-btn ml-10"
                            data-open-pic="{:url('upload_file/index',['type'=>'one','select_id'=>'thumb-select-input'])}">
                        <i class="layui-icon"></i>选择图片
                    </button>
                </div>
                <div class="layui-form-label"></div>
                <div class="layui-input-inline">
                    {notempty name='data.logo'}
                    <div id="thumb-select-input_box" class="pic_box">
                        <dl>
                            <dt><img src="{$data.logo}" data-url="{$data.logo}"></dt>
                            <dd>删除</dd>
                        </dl>
                    </div>
                    {/notempty}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">排序</label>
                <div class="layui-input-block">
                    <input type="number" id="sort" name="sort" autocomplete="off"
                           class="layui-input" value="{$data.sort|default='200'}">
                </div>
                <tip>越小越靠前</tip>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">打开方式</label>
                <div class="layui-input-block">
                    <input type="radio" name="target" value="1"
                           title="新窗口" <?php if($data['target'] == 1) echo "checked" ?>>
                    <input type="radio" name="target" value="0"
                           title="当前窗口" <?php if($data['target'] == 0) echo "checked" ?>>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1"
                           title="启用" <?php if($data['status'] == 1) echo "checked" ?>>
                    <input type="radio" name="status" value="0"
                           title="禁用" <?php if($data['status'] == 0) echo "checked" ?>>
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <input type="hidden" id="id" name="id" value="{$data.id}">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="data-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file='footer'/}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.jquery;

    layui.form.on("submit(data-save)", function (data) {
      layui.$.ajax({
        url: "{:url('links/edit')}",
        type: "POST",
        dateType: "json",
        data: data.field,
        success: function (res) {
          if (res.code !== 200) {
            return hui_msg(res.msg, 2);
          }
          hui_msg(res.msg, 1, function () {
            var pageId = parent.layer.getFrameIndex(window.name);
            parent.layer.close(pageId);
          });
        }
      });
      return false;
    })

  })
</script>
</body>
</html>
